package com.glorysoft.knowlespda.ui.updatecount.viewmodel

import android.app.Activity
import androidx.databinding.ObservableArrayList
import androidx.lifecycle.MutableLiveData
import com.glorysoft.knowlespda.base.BaseViewModel
import com.glorysoft.knowlespda.base.Constant
import com.glorysoft.knowlespda.entity.CountEntity
import com.glorysoft.knowlespda.entity.ui.CallObserveBean
import com.glorysoft.knowlespda.model.CountRepository
import com.glorysoft.knowlespda.model.TrackRepository
import com.glorysoft.knowlespda.utils.MyUtils
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_TabIndexGridEntity
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StringUtils
import me.tatarka.bindingcollectionadapter2.ItemBinding
import java.io.InputStream

/**
 * FileName: HomeViewModel
 * Author: XJH
 * Date: 2021/7/12 17:20
 * Description:
 * History:
 */
class UpdateCountViewModel: BaseViewModel() {

    val repository = CountRepository()

    var countInfo = MutableLiveData<CountEntity>()

    fun getCountInfo(id : String){
        val map = JsonObject()
        map.addProperty("OPID",Constant.CURRENT_USER)
        map.addProperty("MACHINEID",id)
        launchOnlyResult({
            countInfo.value = repository.getCountInfo(map)
        })
    }

    fun updateCount(count : String){
        val map = JsonObject()
        map.addProperty("OPID",Constant.CURRENT_USER)
        map.addProperty("MACHINEID",countInfo.value?.machineid)
        map.addProperty("TOTALNUM",countInfo.value?.totalnum)
        map.addProperty("COUNTING",countInfo.value?.counting)
        map.addProperty("TARGETQTY",count)
        launchOnlyResult({
            repository.updateCount(map)
            defUI.startActivity.call()
        })
    }
}